
libname ps 'D:\Vicky Lantushenko\Research\Dr. Fich\buyingtargets\New bt\Fin Mgmt R_R\Pseudo';
                                                                                                                        
/*INSTITUTIONAL OWNERSHIP AROUND M&A ANNOUNCEMENTS*/

/*TABLE 2*/

 /*variable definitions*/
/*r_lag1 = percent ownership by mutual funds (hedge funds) defined as the total number of shares held by MF (HF)
as a fraction of total shares outstanding multiplied by 100, measured one quarter before the announcement quarter*/
/*r_lag2 = percent ownership by mutual funds (hedge funds) defined as the total number of shares held by MF (HF)
as a fraction of total shares outstanding multiplied by 100, measured two quarters before the announcement quarter
count = quarter time count*/

/*use psuedo-dataset T2*/
data t2;
set ps.t2;
run;
data t2;
set t2;
diff_lag2_lag3=r_lag2-r_lag3;
diff_lag1_lag2=r_lag1-r_lag2;
diff_lag1_lag3=r_lag1-r_lag3;
diff_lag1_lag4=r_lag1-r_lag4;
diff_date=fdate-date_announced;
if diff_date>70 then beg_q=1; else beg_q=0;
if diff_date<20 then end_q=1; else end_q=0;
if tender_offer='Yes' then tender=1;
else tender=0;
if unsolicited='Yes' then hostile=1;
else hostile=0;
if number_of_bidders>1 then multi_bids=1;
else multi_bids=0;
if date_effective ne . then completed=1;
else completed=0;
one=1;
run;
proc univariate data=t2;
var mktcap r_lag5 r_lag4 r_lag3 r_lag2 r_lag1 tender hostile multi_bids completed;
run;
proc univariate data=t2;
var diff_lag1_lag2;
run;
proc surveyreg data=t2;
cluster count;
model diff_lag1_lag2=one;
run;
proc surveyreg data=t2;
cluster count;
model diff_lag1_lag3=one ;
run;
proc surveyreg data=t2;
cluster count;
model diff_lag1_lag4=one ;
run;

/*TABLE 6*/
/*use pseudo-dataset T6*/
data t6;
set ps.t6;
run;
/*variable definitions:
target=a dummy variable equals 1 if a firm is a target firm in the next quarter (t)
mfch_lag1_lag2= change in mutual fund ownership from quarter (t-2) to (t-1)
mfch_lag2_lag3 = change in mutual fund ownership from quarter (t-3) to (t-2)
mfch_lag3_lag4 = change in mutual fund ownership from quarter (t-4) to (t-3)
lag4_mfown = mutual fund ownership in quarter (t-4)
hfch_lag1_lag2 = change in hedge fund ownership from quarter (t-2) to (t-1)
hfch_lag2_lag3 = change in hedge fund ownership from quarter (t-3) to (t-2)
hfch_lag3_lag4 = change in hedge fund ownership from quarter (t-4) to (t-3)
lag4_hfown = hedge fund ownership in quarter (t-4)
ret_3mo = one-quarter stock return
tar_1yrret_t = one-year stock retrun
ret_60mo = five-year stock return
std_ret = standard deviation of stock returns, using 36 monthly observations
log_mcap = the natural logarithm of larket capitalization
m_to_b = market-to-book ratio
debt_equity = debt-to-equity ratio
p_to_earn = price-to-earnings ratio
roe = return on equity
sales_growth = sales growth
liquidity = ratio of new liquid assets to total assets
mergerwave = merger wave dummy
mfstock_flow = mutual fund flow into a stock
hfstock_flow = hedge fund flow into a stock
count = time quarter
SIC2dig = 2-digit SIC*/

/*Panel A of Table 6*/
proc univariate data=t6;
var ret_3mo tar_1yrret_t ret_60mo std_ret
log_mcap m_to_b  debt_equity p_to_earn roe sales_growth liquidity
mergerwave mfstock_flow hfstock_flow;
run;
/*Panel B of Table 6 - model 5*/
proc surveyreg data=t6;
cluster count;
class count SIC2dig;
model target= mfch_lag1_lag2 mfch_lag2_lag3 mfch_lag3_lag4 lag4_mfown
hfch_lag1_lag2 hfch_lag2_lag3 hfch_lag3_lag4
lag4_hfown
ret_3mo tar_1yrret_t ret_60mo std_ret
log_mcap m_to_b  debt_equity p_to_earn roe sales_growth liquidity
mergerwave
mfstock_flow hfstock_flow
count SIC2dig / solution;
run;

/*TABLE 7 Panel B:  Hedge funds*/
/*use pseudo-dataset T7*/
data t7;
set ps.t7;
run;
/*variable 'lag1_perc_w' is the fund's portfolio weight in a target firm at the end of the quarter prior to the 
announcement quarter*/
proc sort data=t7;
by mgrno count;
run;
proc univariate data=t7;
var lag1_perc_w;
run;
proc means data=t7 noprint;
var lag1_perc_w;
output out=t7_a sum(lag1_perc_w)=lag1_w;
by mgrno count;
run;
proc univariate data=t7_a;
var lag1_w;
run;
proc expand data=t7_a out=t7_a method=none;
  by mgrno; id count; 
  convert lag1_w=lag1w_tplus1/transformout=(lead 1);
   convert lag1_w=lag1w_tplus2/transformout=(lead 2);
   convert lag1_w=lag1w_tplus3/transformout=(lead 3);
   convert lag1_w=lag1w_tplus4/transformout=(lead 4);
quit;
data t7_a;
set t7_a;
if lag1_w ne 0;
run;
proc sort data=t7_a;
by count;
run;
proc rank data=t7_a
     groups=3
     out=t7_b;
var lag1_w;
by count;
ranks ranklag1_w;
run;
proc sort data=t7_b;
by  count ranklag1_w;
run;
proc means data=t7_b noprint;
var lag1w_tplus1;
output out=t7_c mean(lag1w_tplus1)=avr_tplus mean(lag1_w) = avr_sort;
by  count ranklag1_w;
run;
PROC TRANSPOSE DATA=t7_c OUT=t7_d prefix=rank_;
 ID ranklag1_w;
 VAR avr_tplus;
 by count;
RUN;
data t7_d;
set t7_d;
diff=rank_2-rank_0;
one=1;
run;
proc univariate data=t7_d;
var rank_0 rank_1 rank_2;
run;
proc model data=t7_d;
         endo diff;
         exog one;
         instruments _exog_;
         parms b0 b1;
         diff=b0 + b1*one;
         fit diff / gmm kernel=(bart,5,0) vardef=n outest=b1;
		 ods output ParameterEstimates=sample5 residsummary=rsquared1; 
         quit;
/* for zero holdings*/
proc means data=t7 noprint;
var lag1_perc_w;
output out=t7_z sum(lag1_perc_w)=lag1_w;
by mgrno count;
run;
proc expand data=t7_z out=t7_z method=none;
  by mgrno; id count; 
   convert lag1_w=lag1w_tplus1/transformout=(lead 1);
   convert lag1_w=lag1w_tplus2/transformout=(lead 2);
   convert lag1_w=lag1w_tplus3/transformout=(lead 3);
   convert lag1_w=lag1w_tplus4/transformout=(lead 4);
quit;
data t7_z;
set t7_z;
if lag1_w eq 0;
run;
proc sort data=t7_z;
by count;
run;
proc univariate data=t7_z;
var lag1_w lag1w_tplus1 lag1w_tplus2 lag1w_tplus3 lag1w_tplus4;
run;
proc means data=t7_z noprint;
var lag1w_tplus1;
output out=t7_zz mean(lag1w_tplus1)=avr_tplus1
mean(lag1w_tplus2)=avr_tplus2 mean(lag1w_tplus3)=avr_tplus3
mean(lag1w_tplus4)=avr_tplus4 mean(lag1_w)=avr_lag1w ;
by  count ;
run;
/*testing for differences highest minus zero*/
proc sql;
create table t7_d as
select  a.*, b. avr_tplus1, b. avr_tplus2, b. avr_tplus3, b. avr_tplus4, b. avr_lag1w
from t7_d a left join t7_zz b
on a.count=b.count;
quit;
data t7_d;
set t7_d;
d_hminz=rank_2-avr_tplus1;
run;
proc model data=t7_d;
         endo d_hminz;
         exog one;
         instruments _exog_;
         parms b0 b1;
         d_hminz=b0 + b1*one;
         fit d_hminz / gmm kernel=(bart,5,0) vardef=n outest=b1;
		 ods output ParameterEstimates=sample5 residsummary=rsquared1;
         quit;


/*TABLE 8: Creating the activeness measures, Active Share and Fund (1-R2),for hedge funds*/
/*use pseudo-dataset T8_as and T8_crsp*/
/*variable 'w' is the portfolio weight in a stock*/
data t8_as;
set ps.t8_as;
run;
data crsp_m;
set ps.t8_crsp;
run;
data act;
set t8_as;
keep mgrno count;
run;
proc sort data=act nodupkey;
by mgrno count;
run;
proc sql;
create table act as
select a.*, b. permno, b. mkt_w
from act a left join crsp_m b
on a.count=b.count 
order by mgrno, count;
quit;
proc sql;
create table act as
select a.*, b. w
from act a left join t8_as b
on a.count=b.count and a.permno=b.permno and a.mgrno=b.mgrno 
order by mgrno, count;
quit;
proc stdize data=act out=act reponly missing=0;
   var w;
run;
data act;
set act;
diff=abs(w-mkt_w);
run;
proc means data=act noprint;
var diff;
output out=act1 sum(diff)=tot_diff;
by mgrno count;
run;
data act1;
set act1;
act_share=tot_diff/2;
run;
proc univariate data=act1;
var act_share;
run;
/*Fund (1-R2)*/
/*use pseudo-dataset t8_r1 and Fama-French dataset with 4 factors*/
data hf_r2;
set ps.t8_r1;
run;
data hf_r2;
set hf_r2;
p_shares=p_crsp*lag_shares;
run;
proc sort data=hf_r2;
by mgrno date;
run;
proc sql;
create table hf_r2 as
select *, sum(p_shares) as portf_value
from hf_r2
group by mgrno, date
order by mgrno,date;
quit;
data hf_r2;
set hf_r2;
w=p_shares/portf_value;
w_ret=w*ret;
run;
proc means data=hf_r2 noprint;
var w_ret;
output out=hf_ret sum(w_ret)=hf_ret;
by mgrno date;
run;
proc univariate data=hf_ret;
var hf_ret;
run;
proc sort data=hf_ret;
by mgrno date;
run;
data hf_ret_a;
     set hf_ret(keep=mgrno date);
     by mgrno date;
     retain firstdate;
     date=intnx('qtr', date, 1)-1;
     if first.mgrno then firstdate=date;
     if last.mgrno then do;
         lastdate=date;
	 output;
     end;
run;
   data hf_ret_b(rename=(date=rankdate));
      set hf_ret_a;
      date=firstdate;
      do while(date<=lastdate);
         output;
	 date=intnx('mon', date+1, 1)-1;
      end;
  run;
data hf_ret_b;
     set hf_ret_b;
     date=rankdate;
     i=1;
     do while(i<=24);
         output;
         date=intnx('mon', date, 0)-1;
	 i=i+1;
     end;
run;
  data hf_ret_c;
      set ps.ff(keep=dateff rf smb hml umd mktrf);
      date=intnx('month', dateff, 1)-1;      
  run;
proc sort data=hf_ret_b;
      by date mgrno;
run;
 data hf_ret_b;
      merge hf_ret_b(in=a) hf_ret_c(in=b);
      by date;
      if a and b;
  run;
  data hf_ret_d;
     set hf_ret (keep=mgrno date hf_ret);
     where hf_ret is not missing;
     date=intnx('mon', date, 1)-1;
  run;
    proc sort data=hf_ret_d nodupkey;
      by date mgrno;
  run;
   data hf_ret_b;
      merge hf_ret_b(in=a) hf_ret_d(in=b);
      by date mgrno;
      if a and b;
  run;
  data hf_ret_b;
     set hf_ret_b;
     exret=hf_ret-rf;
  run;
proc sort data=hf_ret_b;
      by mgrno rankdate;
run;
proc reg data=hf_ret_b noprint outest=hf_ret_e edf ;
      by mgrno rankdate;
      model exret=mktrf smb hml umd;
  run;
data hf_ret_e;
set hf_ret_e;
if _EDF_>=18;
one_rsq=1-_RSQ_;
year=year(rankdate);
month=month(rankdate);
run;

/*TABLE 8 PANEL D*/
/*use t8_act pseudo dataset*/
/*diff_q_01_all is the change in holdings as defined by Eq (1); time is a quarter time count; treat is 
a dummy variable that equals one if a firm is a target firm and 0 otherwise*/
data t8_act;
set ps.t8_act;
run;
proc surveyreg data=t8_act;
cluster mgrno;
class time ind;
model diff_w_01_all=act_share treat act_share*treat
tar_size ret_tmin2 ret_tmin1 turn tot_dollarhold
time ind  / solution;
run;

